package com.yswee.mallnavi.view.company;

import android.content.Context;
import android.view.View;
import android.widget.TextView;

import com.yswee.framework.utils.ViewInject;
import com.yswee.framework.widget.layoutview.MRelativeLayout;
import com.yswee.mallnavi.Preference;
import com.yswee.mallnavi.R;
import com.yswee.mallnavi.entity.common.CompanyEntity;


public class ListItem extends MRelativeLayout<CompanyEntity> {

	@ViewInject
	protected View rlcontent;
	@ViewInject
	protected TextView tvname;
	@ViewInject
	protected TextView tvdesc;
	@ViewInject
	protected View imgselected;

	private ListView.IActionCallback mActionCallback;

	public void setActionCallback(ListView.IActionCallback c) {
		mActionCallback = c;
	}

	public ListItem(Context context) {
		super(context);
	}
	
	@Override
	protected int getLayoutResId() {
		return R.layout.view_company_listitem;
	}
	
	@Override
	protected void onBindListener() {
		super.onBindListener();
		setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				if (mActionCallback != null) {
					mActionCallback.onCompanyClicked(v, mDataItem);
				}
			}
		});
	}

	@Override
	protected void onApplyData() {
		tvname.setText(mDataItem.name);
		tvdesc.setText(mDataItem.description);
		boolean selected = false;
		CompanyEntity company = Preference.getCompany();
		if (company != null && company.id != null && company.id.equals(mDataItem.id)) {
			selected = true;
		}
		imgselected.setVisibility(selected ? View.VISIBLE : View.GONE);
		rlcontent.setBackgroundResource(selected ? R.drawable.view_company_sel_bg : R.drawable.view_company_bg);

	}
	
}
